Importing Data to RStudio

Before you export your data from Google to RStudio, make sure your spreadsheet follows these four guidelines:

  1. Variable names cannot contain spaces, so it is optimal if they are one-word names only. If you want a variable name to be longer than one word, use periods or underscores to act as spaces.
  2. R is case-sensitive, so it is easier if everything is lower case.
  3. The file that you want to upload should only contain the data in canonical form.
  4. If you have other information that you want to keep, save it in a different document, which is called the codebook.

If you have formatted your data correctly, then it can be read as .csv form, which is how R reads your data. Download your properly-formatted spreadsheet as a .csv file by selecting File > Download as > Comma-separated values (.csv). The file will download to your local hard-drive.

Next, open your RStudio browser. In the Files/Plots/Packages/Help pane, upload your data by selecting Files > Upload > Choose File > your_spreadsheet_name.csv. Then, select Open, which uploads your data to RStudio. You will find the name of your data in your list of Files.

To access this data, you will first have to give it a one-word name (let's call this example_data). In the R console, type: example_data = read.csv(“The name of your data frame.csv”). read.csv() is a function that takes a file name as an argument and reads it into the RStudio console under the given name on the left-hand side of the equals sign. The data is now stored in the console as \( \text{example_data} \).

To confirm you loaded the data correctly, try the follow command: \( \text{View(example_data)} \) If the data were loaded correctly, the data frame will open in the source pane.